package com.wanho.java159.cb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanho.java159.cb.mapper.BalanceRechargeRecordMapper;
import com.wanho.java159.cb.po.BalanceRechargeRecord;
import com.wanho.java159.cb.po.BalanceRechargeRecordExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* BalanceRechargeRecord 业务处理类
* @author ChaoFei.Zhang
* @date   2021-07-10
*/
@Service
@Transactional
public class BalanceRechargeRecordService {
    /**BalanceRechargeRecord数据访问层对象*/
    @Resource
    private BalanceRechargeRecordMapper balanceRechargeRecordMapper ;

    /**
    * 查询所有 BalanceRechargeRecord 状态为未删除 is_deleted=0 的数据
    * @return BalanceRechargeRecord所有的数据
    */
    public List<BalanceRechargeRecord> list(){
        BalanceRechargeRecordExample balanceRechargeRecordExample = new BalanceRechargeRecordExample();
        //查询 数据表中 is_deleted = 0
        balanceRechargeRecordExample.createCriteria().andIsDeletedEqualTo(false) ;
        return balanceRechargeRecordMapper.selectByExample(balanceRechargeRecordExample) ;
    }

    /**
    * 根据删除主键删除 BalanceRechargeRecord 逻辑删除 进行is_deleted=1的修改操作
    * @param id BalanceRechargeRecord的主键
    * @return true 删除成功  false 删除失败
    */
    public boolean remove(Long id){
        BalanceRechargeRecord balanceRechargeRecord = new BalanceRechargeRecord();
        balanceRechargeRecord.setId(id);
        balanceRechargeRecord.setIsDeleted(true);
        return balanceRechargeRecordMapper.updateByPrimaryKeySelective(balanceRechargeRecord) > 0 ;
    }

    /**
    * 新增一条BalanceRechargeRecord记录
    * @param  balanceRechargeRecord 封装新增的数据
    * @return true 新增成功  false 新增失败
    */
    public boolean save(BalanceRechargeRecord balanceRechargeRecord){
        balanceRechargeRecord.setCreateTime(new Date());
        balanceRechargeRecord.setUpdateTime(new Date());
        balanceRechargeRecord.setIsDeleted(false);
        return balanceRechargeRecordMapper.insert(balanceRechargeRecord)>0 ;
    }

    /**
    * 根据主键查询 BalanceRechargeRecord
    * @param id BalanceRechargeRecord的主键
    * @return null id不存在  返回BalanceRechargeRecord对象
    */
    public BalanceRechargeRecord get(Long id){
        return balanceRechargeRecordMapper.selectByPrimaryKey(id) ;
    }

    /**
    * 修改一条BalanceRechargeRecord记录
    * @param  balanceRechargeRecord 封装修改的数据
    * @return true 修改成功  false 修改失败
    */
    public boolean update(BalanceRechargeRecord balanceRechargeRecord) {
        balanceRechargeRecord.setUpdateTime(new Date());
        return balanceRechargeRecordMapper.updateByPrimaryKeySelective(balanceRechargeRecord)>0 ;
    }

    /**
    * 分页查询 BalanceRechargeRecord  如果有查询条件需要动态在方法体内添加条件
    * @param pageNum 页码
    * @param pageSize 分页跨度
    * @param balanceRechargeRecord 封装查询的数据
    * @return 分页对象
    */
    public PageInfo<BalanceRechargeRecord> listPage(Long pageNum, Long pageSize,BalanceRechargeRecord balanceRechargeRecord) {
        PageHelper.startPage(pageNum.intValue(),pageSize.intValue());
        BalanceRechargeRecordExample balanceRechargeRecordExample = new BalanceRechargeRecordExample();
        BalanceRechargeRecordExample.Criteria criteria = balanceRechargeRecordExample.createCriteria();
        return new PageInfo<>(balanceRechargeRecordMapper.selectByExample(balanceRechargeRecordExample));
    }
}